<template>
  <div class="app-container">
    <!-- 导航栏部分 -->
    <div class="boss-header">
      <div class="header-container">
        <div class="logo">
          <a href="/">BOSS直聘</a>
        </div>

        <!-- 新城市选择弹窗按钮 -->
        <div class="city-selector-btn" @click="showSelector = true">
          <i class="location-icon"></i>
          <span class="current-city">{{ currentCity }}</span>
          <span class="switch-text">[切换]</span>
        </div>
        <CitySelector v-model:visible="showSelector" @select="onSelectCity" />

        <nav class="main-nav">
          <ul>
            <li><a href="/" :class="{active: activeNav === 'home'}">首页</a></li>
            <li><a href="/jobs" :class="{active: activeNav === 'jobs'}">职位</a></li>
            <li><a href="/company" :class="{active: activeNav === 'company'}">公司</a></li>
            <li class="combo-item">
              <a href="/school" :class="{active: activeNav === 'school'}">校园</a>
              <span class="divider">/</span>
              <a href="/overseas" :class="{active: activeNav === 'overseas'}">海归</a>
            </li>
            <li><a href="/app" :class="{active: activeNav === 'app'}">APP</a></li>
            <li><a href="/discover" :class="{active: activeNav === 'discover'}">有了</a></li>
            <li><a href="/overseas" :class="{active: activeNav === 'abroad'}">海外</a></li>
            <li><a href="/accessible" :class="{active: activeNav === 'accessible'}">无障碍专区</a></li>
          </ul>
        </nav>

        <div class="user-area">
          <!-- 消息按钮 -->
          <div class="message-box" @mouseenter="showMessageTip = true" @mouseleave="showMessageTip = false">
            <a href="/messages" class="message-btn">
              <i class="message-icon"></i>
              <span class="message-count" v-if="unreadCount > 0">{{ unreadCount }}</span>
            </a>
            <div class="message-tip" v-show="showMessageTip">
              <div class="tip-arrow"></div>
              <div class="tip-content">您有{{ unreadCount }}条未读消息</div>
            </div>
          </div>

          <!-- 简历按钮 -->
          <div class="resume-box" @mouseenter="showResumeMenu = true" @mouseleave="showResumeMenu = false">
            <a href="/resume" class="resume-btn">简历</a>
            <div class="resume-menu" v-show="showResumeMenu">
              <a href="/resume/edit" class="menu-item">
                <i class="resume-icon edit-icon"></i>
                <span>在线编辑简历</span>
              </a>
              <a href="/resume/upload" class="menu-item">
                <i class="resume-icon upload-icon"></i>
                <span>上传附件简历</span>
              </a>
              <a href="/resume/template" class="menu-item">
                <i class="resume-icon template-icon"></i>
                <span>简历模板</span>
              </a>
            </div>
          </div>

          <!-- 用户头像 -->
          <div class="user-avatar" @click="toggleUserMenu">
            <span>B</span>
            <div class="user-menu" v-show="showUserMenu">
              <a href="/profile">个人中心</a>
              <a href="/settings">账号设置</a>
              <a href="/logout">退出登录</a>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 搜索框部分 -->
    <div class="search-container">
      <SearchBar @search="handleSearch" />
    </div>
    
    <!-- 主体内容部分 -->
    <div class="main-content">
      <div class="job-categories-container" @mouseleave="handleGlobalMouseLeave">
        <div class="categories-wrapper">
          <!-- 左侧一级分类 -->
          <div class="left-categories" @mouseenter="handleCategoryMouseEnter">
            <div 
              v-for="(level1, index1) in categories" 
              :key="level1.id || index1" 
              class="level1-group"
            >
              <div 
                class="level1-title" 
                @mouseenter="handleLevel1MouseEnter(level1)"
                @click="toggleLevel2(level1)"
                :class="{ active: isLevel1Active(level1) }"
              >
                <span class="level1-icon">
                  <i :class="level1.icon || 'fa fa-briefcase'"></i>
                </span>
                <span class="level1-name">{{ level1.name }}</span>
                <span class="arrow" :class="{ 'rotate': level1.isOpen }">
                  <i class="fa fa-angle-right"></i>
                </span>
              </div>
            </div>
          </div>
          
          <!-- 中间二级分类 -->
          <div 
            v-if="currentLevel1?.isOpen" 
            class="middle-categories"
            @mouseenter="handleCategoryMouseEnter"
          >
            <div 
              v-for="(level2, index2) in currentLevel1.children" 
              :key="level2.id || index2" 
              class="level2-item"
              @mouseenter="handleLevel2MouseEnter(level2)"
              @click="toggleLevel3(level2)"
              :class="{ active: currentLevel2?.id === level2.id }"
            >
              <span class="level2-name">{{ level2.name }}</span>
              <span class="arrow" :class="{ 'rotate': level2.isOpen }">
                <i class="fa fa-angle-right"></i>
              </span>
            </div>
          </div>
          
          <!-- 右侧内容区域 -->
          <div class="right-content">
            <div v-if="loading" class="loading-content">
              <div class="loading-spinner"></div>
              <p>加载中，请稍候...</p>
            </div>
            
            <div v-if="error" class="error-content">
              <i class="fa fa-exclamation-circle"></i>
              <p>{{ error }}</p>
            </div>
            
            <div v-if="searchResult" class="search-result">
              <div class="search-header">
                <h2 class="search-title">搜索结果: "{{ searchKeyword }}"</h2>
                <span class="result-count">{{ searchResult.length }} 个职位</span>
              </div>
              <div class="search-results-grid">
                <a 
                  v-for="(job, index) in searchResult" 
                  :key="index" 
                  :href="`/jobs/${job.id}`" 
                  class="search-result-card"
                >
                  <div class="job-title">{{ job.title }}</div>
                  <div class="company-name">{{ job.company }}</div>
                  <div class="salary">{{ job.salary }}</div>
                </a>
              </div>
            </div>
            
            <div v-if="currentLevel2 && !searchResult" class="content-inner">
              <div class="content-header">
                <div class="breadcrumb">
                  <span class="breadcrumb-item" @click="backToLevel1">{{ currentLevel1?.name || '全部职位' }}</span>
                  <span class="breadcrumb-separator">/</span>
                  <span class="breadcrumb-item active">{{ currentLevel2.name }}</span>
                </div>
                <h2 class="content-title">{{ currentLevel2.name }}</h2>
                <div class="level2-info">
                  <span>{{ currentLevel2.children?.length || 0 }} 个细分领域</span>
                  <span class="divider">|</span>
                  <span>查看全部职位</span>
                </div>
              </div>
              
              <div class="level3-grid">
                <a 
                  v-for="(level3, index3) in currentLevel2.children" 
                  :key="level3.id || index3" 
                  :href="getJobLink(level3)" 
                  class="level3-card"
                >
                  <div class="level3-name-only">{{ level3.name }}</div>
                </a>
              </div>
            </div>
            
            <!-- 仅当鼠标未悬停且未选择分类时显示图片 -->
            <div v-if="shouldShowImages && !searchResult" class="image-grid">
              <div class="image-row">
                <div class="image-item">
                  <img :src="img1" alt="图片1">
                </div>
                <div class="image-item">
                  <img :src="img2" alt="图片2">
                </div>
              </div>
              <div class="image-row">
                <div class="image-item">
                  <img :src="img3" alt="图片3">
                </div>
                <div class="image-item">
                  <img :src="img4" alt="图片4">
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 热招职位区块 -->
    <div class="job-category-section">
      <div class="job-category-page">
        <h1>热招职位</h1>
        <div class="category-nav">
          <el-button
            v-for="(category, index) in firstLevelCategories"
            :key="index"
            @click="handleCateOneClick(category)"
            :class="['category-btn', activeCategoryId === category.id ? 'active' : '']"
            type="primary"
            plain
          >
            {{ category.name }}
          </el-button>
        </div>
        <div v-if="loading" class="loading">
          <el-skeleton :rows="3" animated></el-skeleton>
        </div>
        <div v-if="error" class="error">
          <el-alert type="error" :title="error"></el-alert>
        </div>
        <div v-if="!loading && !error && (!jobpostings || jobpostings.length === 0)" class="empty-state">
          <el-empty description="暂无相关职位信息"></el-empty>
        </div>
        <div class="job-list" v-if="jobpostings && jobpostings.length > 0">
          <div
            v-for="(job, index) in jobpostings"
            :key="index"
            class="job-card"
            @mouseenter="handleMouseEnter(index)"
            @mouseleave="handleMouseLeave(index)"
          >
            <div class="job-info">
              <div class="job-header">
                <h3 class="job-title">{{ job.title }}</h3>
                <span class="salary">{{ job.money }}</span>
              </div>
              <div class="job-meta">
                <span><el-icon><location /></el-icon>{{ job.city.name }}</span>
                <span>{{ job.label }}</span>
                <span><el-icon><school /></el-icon>{{ job.education }}</span>
                <el-icon v-if="job.tags && job.tags.length > 0"><collection-tag /></el-icon>
                <span v-if="job.labels && job.labels.length > 0">{{ job.labels.join(' ') }}</span>
              </div>
              <div class="company-info">
                <img :src="job.company.logo || 'https://picsum.photos/100/100'" alt="Company Logo" class="company-logo" />
                <div class="company-details">
                  <div class="company-name">{{ job.company.name }}</div>
                  <div class="job-meta">{{ job.company.description }}</div>
                </div>
              </div>
            </div>
            <div class="job-actions" :class="{'show-actions': isHoveringIndex === index}">
              <el-button size="small" type="primary" plain>详情</el-button>
              <el-button size="small" type="warning" plain>收藏</el-button>
            </div>
          </div>
        </div>
        <div class="load-more-container" v-if="jobpostings && jobpostings.length > 0">
          <el-button @click="loadMore" type="primary" plain>查看更多</el-button>
        </div>
      </div>
    </div>

    <!-- 热门企业区块 -->
    <div class="hot-jobs-container">
      <h1>热门企业</h1>
      <div class="company-grid">
        <div v-for="company in companies" :key="company.id" class="company-card">
          <!-- 企业信息部分 -->
          <div class="company-info">
            <img :src="company.logo || 'https://picsum.photos/40/40'" alt="企业Logo" class="company-logo">
            <div>
              <h2 class="company-name">{{ company.name }}</h2>
              <div class="company-tags">
                <span>{{ company.tag || '未标注' }}</span>
                <span>{{ company.size || '未标注' }}</span>
                <span>{{ company.industry || '未标注' }}</span>
              </div>
            </div>
          </div>
          <!-- 职位列表 -->
          <div class="job-list">
            <div v-for="job in company.hot_jobs" :key="job.id" class="job-item">
              <div class="job-header">
                <h3 class="job-title">{{ job.title }}</h3>
                <span class="job-salary">{{ job.money }}</span>
              </div>
              <div class="job-meta">
                <span>{{ formatAddress(job.location_name) || '未知城市' }}</span>
                <span>{{ job.experience || '经验不限' }}</span>
                <span>{{ job.education || '学历不限' }}</span>
              </div>
            </div>
          </div>
          <div class="btn-container">
            <button class="view-more-btn">查看更多职位</button>
          </div>
        </div>
      </div>
      <div class="global-btn-container">
        <button class="global-view-more" @click="gotoCompanyList">查看更多企业</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted, watch } from 'vue'
import axios from 'axios'
import CitySelector from '../components/CitySelector.vue'
import SearchBar from '../components/SearchBar.vue'
import {
  Location,
  School,
  CollectionTag
} from '@element-plus/icons-vue'
import { ElEmpty, ElSkeleton, ElTag, ElButton, ElIcon, ElAlert } from 'element-plus'
import img1 from './img/homehua1.png'
import img2 from './img/homehua2.png'
import img3 from './img/homehua3.png'
import img4 from './img/homehua4.png'

// 导航栏相关数据
const currentCity = ref('北京')
const showSelector = ref(false)
const activeNav = ref('home')
const unreadCount = ref(3)
const showMessageTip = ref(false)
const showResumeMenu = ref(false)
const showUserMenu = ref(false)

// 职位分类相关数据
const categories = ref([])
const loading = ref(false)
const error = ref(null)
const currentLevel1 = ref(null)
const currentLevel2 = ref(null)
const hoverTimer = ref(null)
const hoverDelay = 300 // 悬停延迟时间（毫秒）
const isHovering = ref(false) // 鼠标是否悬停在分类上

// 搜索相关数据
const searchKeyword = ref('')
const searchResult = ref(null)

// 热招职位相关数据
const firstLevelCategories = ref([])
const activeCategoryId = ref(null)
const jobpostings = ref([])
const isHoveringIndex = ref(-1)
const page = ref(1)
const pageSize = ref(10)
const total = ref(0)

// 热门企业相关数据
const companies = ref([])

// 地址格式化函数
const formatAddress = (address) => {
  if (!address) return ''
  const municipalityReg = /^(北京|上海|天津|重庆)市?/
  if (municipalityReg.test(address)) {
    const match = address.match(/^(北京|上海|天津|重庆)市?([^区]+区|[^县]+县)/)
    return match ? `${match[1]}市 ${match[2]}` : address
  }
  const provinceReg = /^([^省]+省|.+自治区|.+特别行政区)([^市]+市)([^区]+区|[^县]+县)/
  const match = address.match(provinceReg)
  if (match) {
    return `${match[1]} ${match[2]} ${match[3]}`
  }
  return address
}

// 获取一级分类
const fetchFirstLevelCategories = async () => {
  loading.value = true
  try {
    const response = await axios.get('http://127.0.0.1:8000/home/JobCateOne/')
    if (response.data.code === 200) {
      firstLevelCategories.value = response.data.data
      if (firstLevelCategories.value.length > 0) {
        activeCategoryId.value = firstLevelCategories.value[0].id
        handleCateListClick(activeCategoryId.value)
      }
    } else {
      error.value = response.data.msg || '获取分类数据失败'
    }
  } catch (err) {
    error.value = '网络异常，请重试'
    console.error('请求分类树失败：', err)
  } finally {
    loading.value = false
  }
}

// 获取热招职位列表
const handleCateListClick = async (categoryId) => {
  loading.value = true
  error.value = ''
  page.value = 1
  try {
    const response = await axios.get('http://127.0.0.1:8000/home/jobcateList/', {
      params: {
        jobcate_id: categoryId,
        page: page.value,
        page_size: pageSize.value
      }
    })
    if (response.data.code === 200) {
      let data = response.data.data.results || response.data.data
      data = data.slice(0, 9)
      jobpostings.value = data
      total.value = data.length
    } else {
      error.value = response.data.error || '获取招聘信息失败'
      jobpostings.value = []
    }
  } catch (err) {
    error.value = '网络异常，请重试'
    jobpostings.value = []
    console.error('请求招聘信息失败：', err)
  } finally {
    loading.value = false
  }
}

const handleCateOneClick = (category) => {
  activeCategoryId.value = category.id
  handleCateListClick(category.id)
  const jobList = document.querySelector('.job-list')
  if (jobList) jobList.scrollIntoView({ behavior: 'smooth' })
}

const handleMouseEnter = (index) => {
  isHoveringIndex.value = index
}
const handleMouseLeave = () => {
  isHoveringIndex.value = -1
}
const loadMore = async () => {
  if (jobpostings.value.length >= total.value) return
  page.value++
  loading.value = true
  try {
    const response = await axios.get('http://127.0.0.1:8000/home/jobcateList/', {
      params: {
        jobcate_id: activeCategoryId.value,
        page: page.value,
        page_size: pageSize.value
      }
    })
    if (response.data.code === 200) {
      const newJobs = response.data.data.results || response.data.data
      jobpostings.value = [...jobpostings.value, ...newJobs]
    }
  } catch (err) {
    console.error('加载更多失败：', err)
  } finally {
    loading.value = false
  }
}

// 获取热门企业
const fetchHotCompanies = async () => {
  try {
    const response = await axios.get('http://127.0.0.1:8000/home/hot_job/')
    companies.value = response.data.data || []
  } catch (error) {
    console.error('Error fetching hot companies:', error)
    error.value = '加载热门企业失败'
  }
}

// 页面加载时自动获取数据
onMounted(() => {
  fetchFirstLevelCategories()
  fetchHotCompanies()
})

// 监听活跃分类变化，切换时自动加载职位
watch(activeCategoryId, (newId) => {
  if (newId) {
    handleCateListClick(newId)
  }
})

// 获取分类数据
const fetchCategories = async () => {
  try {
    loading.value = true
    error.value = null
    const response = await axios.get('http://127.0.0.1:8000/home/job-categories/')
    
    if (response.data && Array.isArray(response.data)) {
      categories.value = response.data.map(level1 => ({
        ...level1,
        isOpen: false,
        icon: level1.icon || 'fa fa-briefcase',
        children: level1.children?.map(level2 => ({
          ...level2,
          isOpen: false,
          icon: level2.icon || 'fa fa-code',
          children: level2.children || []
        })) || []
      }))
    } else {
      throw new Error('API返回的数据格式不正确')
    }
  } catch (err) {
    error.value = '加载职位分类失败: ' + (err.response?.data?.message || err.message)
    console.error('加载失败:', err)
  } finally {
    loading.value = false
  }
}

// 处理搜索
const handleSearch = (keyword) => {
  searchKeyword.value = keyword
  if (!keyword.trim()) {
    searchResult.value = null
    return
  }
  
  // 模拟搜索API调用
  loading.value = true
  setTimeout(() => {
    // 实际项目中应替换为真实API请求
    // const response = await axios.get(`/api/jobs/search?q=${keyword}`)
    // searchResult.value = response.data.results || []
    
    // 模拟数据
    searchResult.value = [
      { id: 1, title: `前端开发工程师 (${keyword})`, company: '字节跳动', salary: '15-30K·14薪' },
      { id: 2, title: `后端开发工程师 (${keyword})`, company: '腾讯科技', salary: '20-40K·15薪' },
      { id: 3, title: `UI设计师 (${keyword})`, company: '阿里巴巴', salary: '12-25K·13薪' },
      { id: 4, title: `产品经理 (${keyword})`, company: '百度', salary: '18-35K·14薪' }
    ]
    loading.value = false
  }, 800)
}

// 处理全局鼠标离开（离开整个组件）
const handleGlobalMouseLeave = () => {
  isHovering.value = false
  resetSelection()
}

// 处理分类区域鼠标进入
const handleCategoryMouseEnter = () => {
  isHovering.value = true
}

// 处理一级分类鼠标进入
const handleLevel1MouseEnter = (level1) => {
  if (hoverTimer.value) clearTimeout(hoverTimer.value)
  
  hoverTimer.value = setTimeout(() => {
    if (!level1.isOpen) {
      categories.value.forEach(item => item.isOpen = false)
      level1.isOpen = true
      currentLevel1.value = level1
      if (level1.children?.length) currentLevel2.value = level1.children[0]
    }
    hoverTimer.value = null
  }, hoverDelay)
}

// 处理二级分类鼠标进入
const handleLevel2MouseEnter = (level2) => {
  if (hoverTimer.value) clearTimeout(hoverTimer.value)
  
  hoverTimer.value = setTimeout(() => {
    currentLevel2.value = level2
    hoverTimer.value = null
  }, hoverDelay)
}

// 重置选择状态
const resetSelection = () => {
  if (hoverTimer.value) clearTimeout(hoverTimer.value)
  
  hoverTimer.value = setTimeout(() => {
    if (currentLevel1.value) {
      currentLevel1.value.isOpen = false
      currentLevel1.value = null
      currentLevel2.value = null
    }
    hoverTimer.value = null
  }, hoverDelay)
}

// 点击一级分类
const toggleLevel2 = (level1) => {
  if (level1.isOpen && currentLevel1.value?.id === level1.id) {
    // 如果当前已经打开，则关闭
    level1.isOpen = false
    currentLevel1.value = null
    currentLevel2.value = null
  } else {
    // 否则打开
    categories.value.forEach(item => item.isOpen = false)
    level1.isOpen = true
    currentLevel1.value = level1
    if (level1.children?.length) currentLevel2.value = level1.children[0]
  }
}

// 点击二级分类
const toggleLevel3 = (level2) => {
  if (currentLevel2.value?.id === level2.id) {
    // 如果当前已经选中，则取消选择
    currentLevel2.value = null
  } else {
    // 否则选中
    currentLevel2.value = level2
  }
}

// 判断一级分类是否激活
const isLevel1Active = (level1) => {
  return currentLevel1.value?.id === level1.id
}

// 返回一级分类
const backToLevel1 = () => {
  currentLevel2.value = null
}

// 生成职位链接
const getJobLink = (job) => {
  return `/jobs?category=${job.id}&name=${encodeURIComponent(job.name)}`
}

// 用户菜单切换
const toggleUserMenu = () => {
  showUserMenu.value = !showUserMenu.value
}

// 城市选择回调
const onSelectCity = (city) => {
  currentCity.value = city
}

// 组件挂载时获取数据
onMounted(() => {
  fetchCategories()
})

// 计算属性：是否应该显示图片
const shouldShowImages = computed(() => {
  return !isHovering.value && !currentLevel2.value && !loading.value && !error.value
})
</script>

<style scoped>
/* 全局样式变量 */
:root {
  --primary-color: #00BEBD;
  --secondary-color: #FF7D00;
  --text-primary: #333;
  --text-secondary: #666;
  --text-tertiary: #999;
  --bg-light: #f5f7fa;
  --bg-white: #ffffff;
  --border-color: #e1e4e8;
  --hover-bg: #ebf0f5;
  --search-bg: #f0f2f5;
}

/* 应用容器 */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f0f2f5;
}

/* 导航栏样式 */
.boss-header {
  background-color: #202329;
  color: white;
  height: 49px;
  position: sticky;
  top: 0;
  z-index: 100;
  background-image: url('https://img.bosszhipin.com/static/zhipin/geek/982401352937125536.png.webp');
  background-size: 100% 49px;
  background-repeat: no-repeat;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 20px;
}

.logo a {
  color: #00BEBD;
  font-size: 22px;
  font-weight: bold;
  text-decoration: none;
  margin-right: 30px;
}

.city-selector-btn {
  position: relative;
  margin-right: 30px;
  cursor: pointer;
  padding: 0 10px;
  height: 100%;
  display: flex;
  align-items: center;
}

.city-selector-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.location-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FFFFFF"><path d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7zm0 9.5c-1.38 0-2.5-1.12-2.5-2.5s1.12-2.5 2.5-2.5 2.5 1.12 2.5 2.5-1.12 2.5-2.5 2.5z"/></svg>');
  background-repeat: no-repeat;
  margin-right: 5px;
}

.current-city {
  font-size: 14px;
  color: #FFFFFF;
}

.switch-text {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  margin-left: 4px;
}

.main-nav ul {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

.main-nav li {
  margin: 0 10px;
  position: relative;
}

.main-nav a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 14px;
  padding: 15px 5px;
  display: inline-block;
  transition: all 0.3s;
}

.main-nav a:hover,
.main-nav a.active {
  color: #FFFFFF;
  font-weight: 500;
}

.combo-item {
  display: flex;
  align-items: center;
}

.divider {
  color: rgba(255, 255, 255, 0.3);
  margin: 0 2px;
}

.user-area {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 20px;
}

.message-box {
  position: relative;
}

.message-btn {
  display: flex;
  align-items: center;
  position: relative;
}

.message-icon {
  display: inline-block;
  width: 20px;
  height: 20px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23FFFFFF"><path d="M20 2H4c-1.1 0-1.99.9-1.99 2L2 22l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-2 12H6v-2h12v2zm0-3H6V9h12v2zm0-3H6V6h12v2z"/></svg>');
  background-repeat: no-repeat;
}

.message-count {
  position: absolute;
  top: -5px;
  right: -5px;
  background-color: #FF4D4F;
  color: white;
  font-size: 12px;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: 8px;
  padding: 0 3px;
}

.message-tip {
  position: absolute;
  top: 100%;
  right: 0;
  background: white;
  padding: 8px 12px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  color: #333;
  font-size: 12px;
  white-space: nowrap;
  margin-top: 10px;
}

.message-tip .tip-arrow {
  position: absolute;
  bottom: 100%;
  right: 10px;
  border-width: 0 6px 6px;
  border-style: solid;
  border-color: transparent transparent white;
}

.resume-box {
  position: relative;
}

.resume-btn {
  color: white;
  font-size: 14px;
  padding: 5px 10px;
  border-radius: 4px;
  transition: background-color 0.3s;
}

.resume-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.resume-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: white;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 8px 0;
  min-width: 160px;
  z-index: 10;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  color: #333;
  font-size: 14px;
  text-decoration: none;
}

.menu-item:hover {
  background-color: #f5f5f5;
}

.resume-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-right: 8px;
  background-repeat: no-repeat;
}

.edit-icon {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333333"><path d="M3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.39-.39-1.02-.39-1.41 0l-1.83 1.83 3.75 3.75 1.83-1.83z"/></svg>');
}

.upload-icon {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333333"><path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/></svg>');
}

.template-icon {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23333333"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V5h14v14z"/><path d="M7 12h2v5H7zm8-5h2v10h-2zm-4 7h2v3h-2zm0-4h2v2h-2z"/></svg>');
}

.user-avatar {
  width: 30px;
  height: 30px;
  background-color: #00BEBD;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  cursor: pointer;
  position: relative;
}

.user-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: white;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 8px 0;
  min-width: 120px;
  z-index: 10;
}

.user-menu a {
  display: block;
  padding: 8px 16px;
  color: #333;
  font-size: 14px;
  text-decoration: none;
}

.user-menu a:hover {
  background-color: #f5f5f5;
}

/* 搜索框容器 - 高度减少一半 */
.search-container {
  background-color: var(--bg-white);
  padding: 8px 0; /* 减少padding */
  border-bottom: 1px solid var(--border-color);
  position: sticky;  
  top: 29px;
  z-index: 90;
  box-shadow: 0 1px 3px rgba(255, 255, 255, 0.05);
}

/* 主体内容样式 */
.main-content {
  flex: 1;
  padding: 20px 0;
}

.job-categories-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  background-color: var(--bg-white);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.categories-wrapper {
  display: flex;
  width: 100%;
  height: 100%;
}

.left-categories {
  width: 220px;
  min-width: 220px;
  background-color: var(--bg-light);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
}

.level1-group {
  border-bottom: 1px solid var(--border-color);
}

.level1-title {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}

.level1-title.active {
  background-color: var(--bg-white);
  color: var(--primary-color);
  border-left: 3px solid var(--primary-color);
  padding-left: 13px;
}

.level1-title:hover {
  background-color: var(--hover-bg);
}

.level1-icon {
  width: 20px;
  margin-right: 10px;
  text-align: center;
  color: var(--secondary-color);
}

.level1-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrow {
  width: 16px;
  text-align: center;
  transition: transform 0.3s ease;
  color: var(--text-tertiary);
}

.rotate {
  transform: rotate(90deg);
}

.middle-categories {
  width: 220px;
  min-width: 220px;
  background-color: var(--bg-white);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
}

.level2-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 1px solid var(--border-color);
}

.level2-item.active {
  color: var(--primary-color);
  background-color: var(--hover-bg);
  border-left: 3px solid var(--primary-color);
  padding-left: 13px;
}

.level2-item:hover {
  background-color: var(--hover-bg);
}

.level2-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.right-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  background-color: var(--bg-white);
}

.breadcrumb {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-tertiary);
}

.breadcrumb-item {
  cursor: pointer;
  color: var(--text-secondary);
}

.breadcrumb-item:hover {
  color: var(--primary-color);
}

.breadcrumb-item.active {
  color: var(--text-primary);
  cursor: default;
}

.breadcrumb-separator {
  margin: 0 8px;
  color: var(--border-color);
}

.content-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.content-title {
  font-size: 20px;
  color: var(--text-primary);
  font-weight: 500;
  margin-bottom: 8px;
}

.level2-info {
  display: flex;
  align-items: center;
  font-size: 13px;
  color: var(--text-tertiary);
}

.level2-info span {
  margin-right: 16px;
}

.divider {
  color: var(--border-color);
}

.level3-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.level3-card {
  display: flex;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  transition: all 0.2s;
  text-decoration: none;
  background-color: var(--bg-white);
}

.level3-card:hover {
  border-color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.level3-name-only {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.image-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 0 20px;
}

.image-row {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.image-item {
  flex: 1;
  max-width: 48%;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  transition: all 0.3s ease;
  aspect-ratio: 23/9;
}

.image-item:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.image-item:hover img {
  transform: scale(1.05);
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
}

.loading-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 12px;
}

.error-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #f56c6c;
}

.error-content i {
  font-size: 36px;
  margin-bottom: 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 搜索结果样式 */
.search-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.search-title {
  font-size: 18px;
  color: var(--text-primary);
  font-weight: 500;
}

.result-count {
  font-size: 14px;
  color: var(--text-tertiary);
}

.search-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.search-result-card {
  display: flex;
  flex-direction: column;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  transition: all 0.2s;
  text-decoration: none;
  background-color: var(--bg-white);
}

.search-result-card:hover {
  border-color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.job-title {
  font-size: 16px;
  color: var(--text-primary);
  font-weight: 500;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.company-name {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.salary {
  font-size: 16px;
  color: var(--secondary-color);
  font-weight: bold;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .left-categories, .middle-categories {
    width: 180px;
    min-width: 180px;
  }
  
  .search-results-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

@media (max-width: 768px) {
  .boss-header .header-container {
    padding: 0 10px;
  }
  
  .main-nav {
    display: none;
  }
  
  .header-container {
    justify-content: space-between;
  }
  
  .city-selector-btn {
    margin-right: 15px;
  }
  
  .user-area {
    gap: 10px;
  }
  
  .job-categories-container {
    margin: 0 10px;
  }

  .categories-wrapper {
    flex-direction: column;
  }

  .left-categories, .middle-categories {
    width: 100%;
    max-width: none;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .image-row {
    flex-direction: column;
  }
  
  .image-item {
    max-width: 100%;
  }
  
  .right-content {
    padding: 16px;
  }
  
  .search-results-grid {
    grid-template-columns: 1fr;
  }
}

.job-category-section {
  width: 100%;
  max-width: 1200px;
  margin: 40px auto 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.job-category-page {
  width: 100%;
}
.job-category-page h1 {
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}
.job-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 28px;
  margin-top: 32px;
}
.job-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.07);
  border: 1px solid #f0f0f0;
  transition: box-shadow 0.3s, transform 0.3s;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}
.job-card:hover {
  box-shadow: 0 8px 32px rgba(0,0,0,0.13);
  transform: translateY(-4px) scale(1.02);
}
.job-info {
  padding: 22px 20px 14px 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.job-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.job-title {
  font-size: 17px;
  font-weight: 700;
  color: #222;
}
.salary {
  font-size: 15px;
  color: #ff4d4f;
  font-weight: 600;
}
.job-meta {
  color: #888;
  font-size: 14px;
  margin: 10px 0 14px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.job-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}
.company-info {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fafbfc;
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 10px;
}
.company-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
  border: 1px solid #eee;
}
.company-details {
  flex: 1;
}
.company-name {
  font-size: 15px;
  font-weight: 600;
  color: #222;
  margin-bottom: 2px;
}
.company-details .job-meta {
  font-size: 12px;
  color: #aaa;
  margin: 0;
}
.job-actions {
  position: absolute;
  right: 20px;
  bottom: 20px;
  display: flex;
  gap: 12px;
  opacity: 0;
  transition: opacity 0.3s;
}
.job-card:hover .job-actions {
  opacity: 1;
}
.el-button {
  border-radius: 20px !important;
  font-size: 13px;
  padding: 4px 18px;
  transition: background 0.2s, color 0.2s;
}
.el-button--primary:hover {
  background: #00b26a !important;
  color: #fff !important;
}
.el-button--warning:hover {
  background: #ffb300 !important;
  color: #fff !important;
}
@media (max-width: 900px) {
  .job-list {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  .job-card {
    padding: 0;
  }
}

/* 热门企业区块样式 */
.hot-jobs-container {
  max-width: 1200px;
  margin: 40px auto 0 auto;
  padding: 20px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.hot-jobs-container h1 {
  font-size: 24px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}
.company-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.company-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 28px;
  margin-top: 32px;
}

.company-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.07);
  border: 1px solid #f0f0f0;
  transition: box-shadow 0.3s, transform 0.3s;
  padding: 0 0 16px 0;
  display: flex;
  flex-direction: column;
  min-height: 260px;
  position: relative;
}
.company-card:hover {
  box-shadow: 0 8px 32px rgba(0,0,0,0.13);
  transform: translateY(-4px) scale(1.02);
}

.company-info {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 20px 10px 20px;
  border-bottom: 1px solid #f5f5f5;
}
.company-logo {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  background: #fff;
  border: 1px solid #eee;
}
.company-name {
  font-size: 17px;
  font-weight: 700;
  color: #222;
  margin-bottom: 4px;
}
.company-tags {
  display: flex;
  gap: 10px;
  font-size: 13px;
  color: #aaa;
  margin-top: 2px;
}

.job-list {
  padding: 10px 20px 0 20px;
}
.job-item {
  padding: 10px 0;
  border-bottom: 1px solid #f5f5f5;
}
.job-item:last-child {
  border-bottom: none;
}
.job-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.job-title {
  font-size: 15px;
  font-weight: 600;
  color: #222;
  margin: 0;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.job-salary {
  font-size: 15px;
  font-weight: 600;
  color: #ff6600;
}
.job-meta {
  display: flex;
  gap: 12px;
  font-size: 13px;
  color: #999;
}

.btn-container {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}
.view-more-btn {
  background-color: #fff;
  border: 1px solid #00b26a;
  color: #00b26a;
  border-radius: 20px;
  padding: 6px 18px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.view-more-btn:hover {
  background-color: #f8fff9;
  color: #009e5a;
}

.global-btn-container {
  display: flex;
  justify-content: center;
  margin-top: 40px;
  padding-bottom: 20px;
  border-top: 1px solid #f0f0f0;
}
.global-view-more {
  background-color: #00b26a;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 12px 30px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(0, 178, 106, 0.2);
}
.global-view-more:hover {
  background-color: #009e5a;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 178, 106, 0.3);
}

@media (max-width: 992px) {
  .company-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 768px) {
  .company-grid {
    grid-template-columns: 1fr;
  }
}
</style>